<template>
  <div class="box">
    <header class="header">分类</header>
    <div class="content kind">
      <van-sidebar v-model="activeKey" @change="onChange">
        <van-sidebar-item v-for="item in columnList" :key="item" :title="item" />
      </van-sidebar>
      <van-grid>
        <van-grid-item :icon="item.logo" :text="item.brand" v-for="item in brandList" :key="item.brand" @click="searchBrand(item.brand)" />
      </van-grid>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { Sidebar, SidebarItem, Grid, GridItem } from 'vant'

import { getColumn, getColumnBrand } from '../../api/index.js'

Vue.use(Sidebar)
Vue.use(SidebarItem)
Vue.use(Grid)
Vue.use(GridItem)

export default {
  data () {
    return {
      activeKey: 0,
      columnList: [],
      brandList: []
    }
  },
  mounted () {
    getColumn().then(res => {
      // console.log(res.data.data)
      this.columnList = res.data.data
      this.onChange(0)
    })
  },
  methods: {
    onChange (idx) {
      this.activeKey = idx
      getColumnBrand({
        column: this.columnList[idx]
      }).then(res => {
        this.brandList = res.data.data
      })
    },
    searchBrand (brand) {
      // console.log(this.columnList[this.activeKey], brand)
      const c = this.columnList[this.activeKey]
      this.$router.push('/brandList?column=' + c + '&brand=' + brand)
    }
  }
}
</script>

<style lang="scss">
.kind{
  display: flex;
}
.van-sidebar{
  width: 1.2rem;
}
.van-grid{
  align-self: flex-start;
  width: 100%;
}
</style>
